package com.lengmomo.games.service.impl;

import com.lengmomo.games.service.IChessService;
import com.lengmomo.games.websocket.ChessWebSocketServer;
import com.lengmomo.games.websocket.JqWebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author lengmomo
 * @Date 2023/11/13 16:46
 * @Version 1.0
 */
@Service
public class ChessServiceImpl implements IChessService {

    @Autowired
    private ChessWebSocketServer cws;

    @Override
    public ModelMap getOnlineUser() {
        ModelMap modelMap = new ModelMap();
        List<String> collect = cws.getOnlineUsers().entrySet().stream().map(o -> o.getKey()).collect(Collectors.toList());
        modelMap.put("data", collect);
        return modelMap;
    }

    @Autowired
    private JqWebSocketServer jws;

    @Override
    public ModelMap getJqOnlineUser() {
        ModelMap modelMap = new ModelMap();
        List<String> collect = jws.getOnlineUsers().entrySet().stream().map(o -> o.getKey()).collect(Collectors.toList());
        modelMap.put("data", collect);
        return modelMap;
    }
}
